<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>城市系统</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <<div class="fieldBox">
                <div class="label">城市名称</div>
                <div class="field">
                    <input name="orgNm" id="orgNm" type="text" class="ui-textbox" value=""/>
                </div>
                <div class="fieldBox col_100" style="display:none;">
                    <div class="field">
                        <input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
                    </div>
                </div>
            </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" onclick="searchBtn();" class="sq-button-round">查询</span>
	                <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
             </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>


<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		//initEvent();
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
	    var id = $("#dataId").val();
		$("#ligergrid1").ligerGrid({
			url: '<%=path%>/mcr/mcrCityChannel/initOrgList.do?id='+id,
            method: 'get',
            columns: [
                {display: '省市编码', name: 'orgCd', minWidth: 100, align: 'center', enabledSort: false},
                {display: '省市名称', name: 'orgNm', minWidth: 100, align: 'center', enabledSort: false},
            ],
            pageSize: 200,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	}
	
	


    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    
  //定义父级调用事件
	frameElement.dialog.onOk = function () {
		save();
	}
	
	frameElement.dialog.onCancel = function () {
		frameElement.dialog.close();
	}
	
  //新增
	function save(){
		var data = new Array();//获取表单数据
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length < 1){
			UIUtils.alertError("请至少选择一条数据");
			return;
		}
		var ids = [];
		for(var i=0;i<selectedRows.length;i++){
			var id = selectedRows[i].orgCd;
			ids[i] = id;
            var orgNm = selectedRows[i].orgDispNm;
            orgNm[i] = orgNm;
		}
		data["ids"] = JSON.stringify(ids);
        data["orgNm"] = JSON.stringify(orgNm);
        var dataId = $("#dataId").val();
        if(StringUtils.isEmpty(dataId)){
            $.ligerDialog.SQalert({content:"主键为空！！！",SQ_type: "error"});
        }
        var url = '<%=path%>/mcr/mcrCityChannel/modify.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {ids: JSON.stringify(ids),orgNms: JSON.stringify(orgNm) ,dataId: dataId},
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    //searchBtn();
                    parent.grid.reload();
                    //parent.$.ligerDialog.SQalert({content:'提示内容', SQ_type: "success"});
                    UIUtils.alertSuccess("操作成功!");
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
	}
  
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "loanId":"",
		    "accountId":""
		  });
	}
</script>

</body>
</html>
